import 'package:ichinesereader/models/school/SchoolAdmin.dart';
import 'package:ichinesereader/models/book/AnswerKey.dart';
import 'dart:convert';

class MaxScore {
  MaxScore({
    this.answerKey,
    this.bookId,
    this.entry,
    this.gradedAnswers,
    this.gradedAnswersString,
    this.id,
    this.language,
    this.numAttempts,
    this.pass,
    this.percentage,
    this.points,
    this.schoolAdmin,
    this.score,
    this.simple,
    this.submittedAnswers,
    this.when,
  });

  AnswerKey? answerKey;
  String? bookId;
  String? entry;
  //AnswerKey? gradedAnswers;
  Map<String, bool>? gradedAnswers;
  String? gradedAnswersString;
  String? id;
  String? language;
  int? numAttempts;
  bool? pass;
  int? percentage;
  int? points;
  SchoolAdmin? schoolAdmin;
  int? score;
  bool? simple;
  //AnswerKey? submittedAnswers;
  Map<String, List<String>>? submittedAnswers;
  int? when;

  factory MaxScore.fromJson(Map<String, dynamic> json) => MaxScore(
        answerKey: json["answerKey"] != null
            ? AnswerKey.fromJson(json["answerKey"])
            : null,
        bookId: json["bookId"],
        entry: json["entry"],
        // gradedAnswers: json["gradedAnswers"] != null
        //     ? AnswerKey.fromJson(json["gradedAnswers"])
        //     : null,
        gradedAnswers: Map.from(json["gradedAnswers"])
            .map((k, v) => MapEntry<String, bool>(k, v)),
        gradedAnswersString: json["gradedAnswersString"],
        id: json["id"],
        language: json["language"],
        numAttempts: json["numAttempts"],
        pass: json["pass"],
        percentage: json["percentage"],
        points: json["points"],
        schoolAdmin: json["schoolAdmin"] != null
            ? SchoolAdmin.fromJson(json["schoolAdmin"])
            : null,
        score: json["score"],
        simple: json["simple"],
        submittedAnswers: json["submittedAnswers"] != null
            ? Map.from(json["submittedAnswers"]).map((k, v) =>
                MapEntry<String, List<String>>(
                    k, List<String>.from(v.map((x) => x))))
            : null,
        when: json["when"],
      );

  Map<String, dynamic> toJson() => {
        "answerKey": answerKey != null ? answerKey?.toJson() : null,
        "bookId": bookId,
        "entry": entry,
        //"gradedAnswers": gradedAnswers != null ? gradedAnswers?.toJson() : null,
        "gradedAnswers": Map.from(gradedAnswers!)
            .map((k, v) => MapEntry<String, dynamic>(k, v)),
        "gradedAnswersString": gradedAnswersString,
        "id": id,
        "language": language,
        "numAttempts": numAttempts,
        "pass": pass,
        "percentage": percentage,
        "points": points,
        "schoolAdmin": schoolAdmin != null ? schoolAdmin?.toJson() : null,
        "score": score,
        "simple": simple,
        "submittedAnswers": submittedAnswers != null
            ? Map.from(submittedAnswers!).map((k, v) =>
                MapEntry<String, dynamic>(
                    k, List<dynamic>.from(v.map((x) => x))))
            : null,
        "when": when,
      };
}

Map<String, List<String>> submittedAnswersFromJson(String str) =>
    Map.from(json.decode(str)).map((k, v) =>
        MapEntry<String, List<String>>(k, List<String>.from(v.map((x) => x))));

String submittedAnswersToJson(Map<String, List<String>> data) =>
    json.encode(Map.from(data).map((k, v) =>
        MapEntry<String, dynamic>(k, List<dynamic>.from(v.map((x) => x)))));
